package com.ant.storage.service.impl;

import com.ant.storage.pojo.HouseAccount;
import com.ant.storage.mapper.HouseAccountMapper;
import com.ant.storage.pojo.UserInfo;
import com.ant.storage.service.IHouseAccountService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.ServletContext;
import java.util.Date;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author melon
 * @since 2023-11-13
 */
@Service
public class HouseAccountServiceImpl extends ServiceImpl<HouseAccountMapper, HouseAccount> implements IHouseAccountService {

    @Autowired
    public ServletContext servletContext;

    @Override
    public void houseAccountSave(HouseAccount dto) {
        UserInfo userInfo = (UserInfo) servletContext.getAttribute("userInfo");
        dto.setCreateBy(userInfo.getUserName());
        dto.setCreationTime(new Date());
        if(dto.getId()==null){
            this.baseMapper.insert(dto);
        }else {
            this.baseMapper.updateById(dto);
        }
    }
}
